local skel = fk.CreateSkill {
  name = "lb__zhijian",
  tags = { Skill.Compulsory, Skill.Switch },
  dynamic_desc = function (self, player, lang)
    return player:getSwitchSkillState("lb__zhijian") == fk.SwitchYang and "lb__zhijian_yang" or "lb__zhijian_yin"
  end,
}

Fk:loadTranslationTable {
  ["lb__zhijian"] = "智剑",
  [":lb__zhijian"] = "<b>锁定技</b>，<b>转换技</b>，阳：当你使用锦囊牌后，进入「<b>智剑</b>」并摸一张牌；阴：当你使用非虚拟基本牌后，脱离「<b>智剑</b>」；进入「<b>智剑</b>」后，你的手牌上限翻倍且所有红色手牌均视为【杀】。",

  [":lb__zhijian_yang"] = "<b>锁定技</b>，<b>转换技</b>，<font color=\"#E0DB2F\">阳：当你使用锦囊牌后，进入「<b>智剑</b>」并摸一张牌；</font>阴：当你使用非虚拟基本牌后，脱离「<b>智剑</b>」；进入「<b>智剑</b>」后，你的手牌上限翻倍且所有红色手牌均视为【杀】。",
  [":lb__zhijian_yin"] = "<b>锁定技</b>，<b>转换技</b>，阳：当你使用锦囊牌后，进入「<b>智剑</b>」并摸一张牌；<font color=\"#E0DB2F\">阴：当你使用非虚拟基本牌后，脱离「<b>智剑</b>」；</font>进入「<b>智剑</b>」后，你的手牌上限翻倍且所有红色手牌均视为【杀】。",

  ["@@lb__zhijian"] = "智剑",

  ["$lb__zhijian1"] = "哼，不过一合之敌。",
  ["$lb__zhijian2"] = "强者当前，不吝赐教。",
  ["$lb__zhijian3"] = "哦？你能接我几招？",
  ["$lb__zhijian4"] = "剑形如水，不可久驻。",
}

--- 获取玩家手牌上限。
---@return integer
local getMaxCards = function(self, s)
  local baseValue = math.max(self.hp, 0)

  local status_skills = Fk:currentRoom().status_skills[MaxCardsSkill] or Util.DummyTable
  local max_fixed = nil
  for _, skill in ipairs(status_skills) do
    if skill ~= s then --排除
      local f = skill:getFixed(self)
      if f ~= nil then
        max_fixed = max_fixed and math.max(max_fixed, f) or f
      end
    end
  end

  if max_fixed then baseValue = math.max(max_fixed, 0) end

  for _, skill in ipairs(status_skills) do
    local c = skill:getCorrect(self)
    baseValue = baseValue + (c or 0)
  end

  return math.max(baseValue, 0)
end

skel:addEffect(fk.CardUsing, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player == target and
        (
          (data.card.type == Card.TypeTrick and player:getSwitchSkillState(skel.name) == fk.SwitchYang) or
          (data.card.type == Card.TypeBasic and not data.card:isRuleVirtual() --修改 非虚拟牌
            and player:getSwitchSkillState(skel.name) == fk.SwitchYin)
        )
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@lb__zhijian", player:getSwitchSkillState(skel.name))
    data.extra_data = data.extra_data or {}
    if player:getSwitchSkillState(skel.name) == 1 and not data.extra_data.lb__kuaiyu then
      player:drawCards(1, skel.name)
    end
  end,
})

skel:addEffect("filter", {
  card_filter = function(self, card, player)
    return player:hasSkill(skel.name) and player:getSwitchSkillState(skel.name) == fk.SwitchYin
        and card.color == Card.Red and table.contains(player:getCardIds("h"), card.id)
  end,
  view_as = function(self, player, card)
    local c = Fk:cloneCard("slash", card.suit, card.number)
    c.skillName = skel.name
    return c
  end,
})

skel:addEffect("maxcards", {
  fixed_func = function(self, player)
    if player:hasSkill(skel.name) and player:getSwitchSkillState(skel.name) == fk.SwitchYin then
      return getMaxCards(player, self) * 2
    end
  end
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@@lb__zhijian", 0)
end)

return skel
